<!DOCTYPE html>
<html>
<head>
    {include file="../application/common/header.html" /}
</head>

<body>
    <table id="student_problem_scoredg">
        <thead>
            <tr>
                <th data-options="field:'班号',width:50">班号</th>
                <th data-options="field:'学号',width:50">学号</th>
                <th data-options="field:'姓名',width:50">姓名</th>
                <th data-options="field:'学科',width:50">学科</th>
                <th data-options="field:'总分',width:50">总分</th>
            </tr>
        </thead>
    </table>
    <div id="student_problem_scoretb">
        <form id="student_problem_scoreForm" class="m5">
            <div>
                学期：
                <select class="easyui-combobox" name="termId" id="termId" data-options="width:120,panelHeight:'auto',value:'请选择', editable:false,textField:'学期名称',valueField:'ID',url:'/compent/Util/termList',onSelect:changeTerm"></select>
                <select id="gradeId" class="easyui-combobox" data-options="width:80,panelHeight:'auto', editable:false,url:'/compent/Util/gradeNameList',onSelect:changeGrade"></select>
                <select id="examId" class="easyui-combobox" data-options="width:120,panelHeight:'auto',editable:false,onSelect:changeExam"></select>
                <select id="subject" class="easyui-combobox" data-options="width:60,panelHeight:'auto',editable:false"></select>
                <select id="clazz" class="easyui-combobox" data-options="width:60,editable:false"></select>
                批量学生：<input class="easyui-textbox" id="studentNames" name="studentNames">
                <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-search'" onclick="queryOk('student_problem_score')">查询</a>
                <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-clear'" onclick="resetForm1('student_problem_score')">重置</a>
                <a class="easyui-linkbutton" href="javascript:void(0)" data-options="iconCls:'icon-save'" onclick="zoutExcel('student_problem_score','/examScore/student_problem_score')">导出为EXCEL</a>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        $(function(){
            var url = "";
            $("#student_problem_scoredg").datagrid({
                url: "/examScore/student_problem_score/pageQuery.html",
                rownumbers:true,
                striped:true,
                border:false,
                pagination:true,
                pageSize:30,
                fitColumns:true,
                fit:true,
                toolbar: '#student_problem_scoretb'
            })
        })  
        function changeTerm(record){
            var gradeId = $('#gradeId').combobox('getValue');
            loadParam(record.ID,gradeId)
        }
        function changeGrade(record){
            var termId = $('#termId').combobox('getValue');
            loadParam(termId,record.value)
            var termKey = '<?php echo currTerm()["termKey"]?>';
            var grade = getGrade(termKey,record.value);
            var url="/compent/Util/clazzList?grade="+grade;
            $('#clazz').combobox('setValue','');
            $('#clazz').combobox('reload',url);
        }
        function changeExam(record) {
            loadSubject(record.value);
        }
        function loadParam(termId,gradeId) {
            if(!gradeId) return;
            var url="/compent/util/getTermExam?termId="+termId+"&grade="+gradeId;
            $('#examId').combobox('setValue','');
            $('#examId').combobox('reload',url);
            var examId = $('#examId').combobox('getValue');
            loadSubject(examId);
        }
        function loadSubject(examId) {
            if(examId) {
                var url="/examScore/clazz_subject_strength/examSubject?examId="+examId;
                $('#subject').combobox('setValue','');
                $('#subject').combobox('reload',url);
            }
        }
        function resetForm1(cf){
            $("#" + cf + "Form")[0].reset();
            $("#" + cf + "Form #termId").combobox('setValue', "请选择");
            $("#" + cf + "Form #grade").combobox('setValue', "请选择");
            $("#" + cf + "Form #examId").datebox('setValue', null);
            $("#" + cf + "Form #subject").datebox('setValue', null);
            $("#" + cf + "Form #clazz").datebox('setValue', null);
        }
        function queryOk(){
            var examId = $('#examId').combobox('getValue');
            var clazz = $('#clazz').combobox('getValue');
            var subject = $('#subject').combobox('getValue');
            var gradeId = $('#gradeId').combobox('getValue');
            var studentNames = $('#studentNames').textbox('getValue');
            if(examId && subject){
                var termName = $('#termId').combobox('getText');
                var termKey = termName.substr(termName,4);
                var grade = getGrade(termKey,gradeId);
                $.post("/examScore/student_problem_score/subjectProblemScore",{examId:examId,subject:subject},function(data){
                    var txArr=data.split(",");
                    var zdArr=[{field:'班号',title:'班号',width:50},{field:'学号',title:'学号',width:50},{field:'姓名',title:'姓名',width:50},{field:'学科',title:'学科',width:50},{field:'总分',title:'总分',width:50}];   
                    var txshu=txArr.length;
                    var fieldArray = [];
                    for(var i=0;i<=txshu-1;i++){
                        title=txArr[i];
                        name=title.split(":")[0];
                        if(name != '总分') {
                            fieldArray.push(name);
                        }
                        zdArr.push({field:name,title:title,width:80})
                    }
                    $("#student_problem_scoredg").datagrid({columns:[zdArr]});
                    $('#student_problem_scoredg').datagrid('load',{grade:grade,examId:examId,clazz:clazz,subject:subject,studentNames:studentNames,field:fieldArray.toString()});
                })
            }else{
                $.messager.alert('操作提示','请选择考试名称和学科。');
            }
        }
        function zoutExcel(cf, url){
            var examId = $('#examId').combobox('getValue');
            var clazz = $('#clazz').combobox('getValue');
            var subject = $('#subject').combobox('getValue');
            var gradeId = $('#gradeId').combobox('getValue');
            var studentNames = $('#studentNames').textbox('getValue');
            if(examId && subject){
                var termName = $('#termId').combobox('getText');
                var termKey = termName.substr(termName,4);
                var grade = getGrade(termKey,gradeId);
                $.post("/examScore/student_problem_score/subjectProblemScore",{examId:examId,subject:subject},function(data){
                    var txArr=data.split(",");
                    var txshu=txArr.length;
                    var fieldArray = [];
                    for(var i=0;i<=txshu-1;i++){
                        title=txArr[i];
                        name=title.split(":")[0];
                        if(name != '总分') {
                            fieldArray.push(name);
                        }
                    }
                    window.location.href = url+"/exportExcel.html?grade="+grade+"&examId="+examId+"&clazz="+clazz+"&subject="+subject+"&studentNames="+studentNames+"&field="+fieldArray.toString();
                })
            }else{
                $.messager.alert('操作提示','请选择考试名称和学科。');
                return;
            }
        }
    </script>
</body>
</html>